/* @(#)GSBalanceFeeDAO.java    V0.1
 *
 * Project: GS
 *
 * Modify Information:
 * =============================================================================
 *   Author       Date       Description
 *   ------------ ---------- ---------------------------------------------------
 *   owen         2006-5-17
 *   Jenny li     2006-6-8   新增方法getFeeTypeNo
 * Copyright Notice:
 * =============================================================================
 *    Copyright (c) 2001-2006 Beijing HiTRUST Technology Co., Ltd. 1808 Room, 
 *        Science & Technology Building, No. 9 South Street, Zhong Guan Cun, 
 *        Haidian District, Beijing ,100081, China All rights reserved.
 *
 *    This software is the confidential and proprietary information of
 *        Beijing HiTRUST Technology Co., Ltd. ("Confidential Information").
 *        You shall not disclose such Confidential Information and shall use it
 *        only in accordance with the terms of the license agreement you entered
 *        into with HiTRUST.
 *
 * Warning:
 * =============================================================================
 * 
 */
package com.hitrust.gs.dao;

import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.util.ArrayList;

import com.hitrust.gs.bean.GSBalanceFeeBean;
import com.hitrust.gs.lib.GSLogWriter;
import com.hitrust.gs.lib.db.GSBaseDAO;
import com.hitrust.gs.util.exception.GSException;

/**
 * 
 */
public class GSBalanceFeeDAO extends GSBaseDAO{
    /**
     * 查询所有费用类型
     * @return
     * @throws GSException
     */
    public ArrayList queryAllFeeType() throws GSException{
        ArrayList tList = new ArrayList();
        String tSql = "select * from GS_BALANCE_FEE order by GS_DIS_NO";
        try{
            tList = this.executeQuery(new GSBalanceFeeBean(),tSql,null);
        }catch(Exception e){
            GSLogWriter.error(this,e.toString());
            throw new GSException(GSException.E19999,GSException.E19999_MSG);
        }
        return tList;
    }
    /**
     * 查询费用类型名称
     * @param aFeeTypeNo    费用类型序号
     * @return
     * @throws GSException
     */
    public String queryFeeType(String aFeeTypeNo) throws GSException{
        String tName = "";
        String tSql = "select GS_FEE_TYPE from GS_BALANCE_FEE where GS_FEE_TYPE_NO='" + aFeeTypeNo + "'";
        Connection tConn = null;
        PreparedStatement tStmt = null;
        ResultSet tRs = null;
        try{
            tConn = getConnetion();
            tStmt = tConn.prepareStatement(tSql);
            tRs = tStmt.executeQuery();
            if(tRs.next()){
                tName = tRs.getString(1);
            }
            tRs.close();
            tRs = null;
            tStmt.close();
            tStmt = null;
            tConn.close();
            tConn = null;
        }catch(Exception e){
            GSLogWriter.error(this,e.toString());
            throw new GSException(GSException.E19999,GSException.E19999_MSG);
        }finally{
            try{
                if(tRs != null){
                    tRs.close();
                    tRs = null;
                }
                if(tStmt != null){
                    tStmt.close();
                    tStmt = null;
                }
                if(tConn != null){
                    tConn.close();
                }
                
            }catch(Exception e){
                e.printStackTrace();
            }
        }
        return tName;
    }
    /**
     * 在结算费用表GS_BALANCE_FEE中新增一笔记录
     * 
     * @param aGSBalanceFeeBean
     * 
     * @return boolean
     * 
     * @throws CUPSException
     */
    public boolean add(GSBalanceFeeBean aGSBalanceFeeBean) throws GSException {

        String tSql="INSERT INTO GS_BALANCE_FEE (GS_FEE_TYPE_NO,GS_FEE_TYPE,GS_DIS_NO) VALUES(?,?,?)";

        Object[] tObject = new Object[3] ;
          tObject[0]=aGSBalanceFeeBean.getGs_fee_type_no();
          tObject[1]=aGSBalanceFeeBean.getGs_fee_type();
          tObject[2]=aGSBalanceFeeBean.getGs_dis_no();
          
        boolean tResult = false;
        try {
            tResult = executeUpdate(tSql, tObject);

        } catch (Exception ex) {
            GSLogWriter.error(this, ex.toString());
            throw new GSException(ex.getMessage());
        }

        return tResult;
    }
    
    /**
     * 在结算费用表GS_BALANCE_FEE中更新一笔记录
     * 
     * @param aGSBalanceFeeBean
     * @throws CUPSException]
     * @return boolean
     */
    public boolean modify(GSBalanceFeeBean aGSBalanceFeeBean) throws GSException {

        String tSql = "UPDATE GS_BALANCE_FEE SET GS_FEE_TYPE = ?,GS_DIS_NO=? WHERE GS_FEE_TYPE_NO = ?";
        Object[] tObject = new Object[3];
        tObject[0] = aGSBalanceFeeBean.getGs_fee_type();
        tObject[1] = aGSBalanceFeeBean.getGs_dis_no();
        tObject[2] = aGSBalanceFeeBean.getGs_fee_type_no();       

        boolean tResult = false;
        try {
            tResult = executeUpdate(tSql, tObject);
        } catch (Exception ex) {
            GSLogWriter.error(this, ex.getMessage());
            throw new GSException(ex.getMessage());
        }

        return tResult;
    }
    
    /**
     * 在结算费用表GS_BALANCE_FEE中删除一笔记录
     * 
     * @param aTypeNo
     *            序列号
     */
    public boolean delete(String aTypeNo) throws GSException {
        String tSql = "delete from GS_BALANCE_FEE where GS_FEE_TYPE_NO=?";
        Object[] tObject = { aTypeNo };
        boolean tResult = false;
        try {
            tResult=executeUpdate(tSql, tObject);
        } catch (Exception ex) {
            GSLogWriter.error(this, ex.getMessage());
            throw new GSException(ex.getMessage());
        }

        return tResult;
    }
    /**
     * 查询一个结算费用信息
     * @param aFeeTypeNo
     * @return
     * @throws GSException
     */
    public GSBalanceFeeBean getFeeType(String aFeeTypeNo) throws GSException {
        String tSql = "select * from GS_BALANCE_FEE where GS_FEE_TYPE_NO =?";
        ArrayList tList = null;
        GSBalanceFeeBean tGSBalanceFeeBean = null;
        Object[] tObj = {aFeeTypeNo};
        try{
            tList = this.executeQuery(new GSBalanceFeeBean(),tSql,tObj);
            tGSBalanceFeeBean= (GSBalanceFeeBean)tList.get(0);
        }catch(Exception e){
            GSLogWriter.error(this,e.toString());
            throw new GSException(GSException.E19999,GSException.E19999_MSG);
        }
                
        return tGSBalanceFeeBean;
    }
    /**
     * 根据费用名称查询费用类型序号
     * @param aFeeTypeName
     * @return
     * @throws GSException
     */
    public String getFeeTypeNo(String aFeeTypeName) throws GSException {
        String tSql = "select * from GS_BALANCE_FEE where GS_FEE_TYPE =?";
        ArrayList tList = null;
        String tNo = "";
        Object[] tObj = {aFeeTypeName};
        try{
            tList = this.executeQuery(new GSBalanceFeeBean(),tSql,tObj);
            tNo = ((GSBalanceFeeBean)tList.get(0)).getGs_fee_type_no();
        }catch(Exception e){
            GSLogWriter.error(this,e.toString());
            throw new GSException(GSException.E19999,GSException.E19999_MSG);
        }
                
        return tNo;
    }
}
